package com.example.zqh.utils;

import com.example.zqh.model.RespBean;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 全局异常
 * zqh
 */
@ControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(com.example.zqh.utils.ParamsException.class)
    @ResponseBody
    public RespBean paramsExceptionHandler(com.example.zqh.utils.ParamsException e) {
        System.out.println(e.getMessage());
        return RespBean.error(e.getMsg());
    }

    @ExceptionHandler(AccessDeniedException.class)
    @ResponseBody
    public RespBean AccessDeniedException(AccessDeniedException e) {
        System.out.println(e);
        return RespBean.error("权限不足");
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public RespBean ExceptionHandler(Exception e) {
        System.out.println(e);
        return RespBean.error(e.getMessage());
    }


}
